package com.dpj.book.servlet;

import com.alibaba.fastjson.JSONObject;
import com.dpj.book.pojo.Book;
import com.dpj.book.service.BookService;
import com.dpj.book.service.impl.BookServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/book/*")
public class BookServlet extends BaseServlet{
    private BookService bookService=new BookServiceImpl();
    public void selectAllBooks(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 设置响应数据的中文乱码
        response.setContentType("text/html;charset=utf-8");
        List<Book> books=bookService.SelectAllBooks();
        String s = JSONObject.toJSONString(books);
        response.getWriter().write(s);
    }
}
